<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>商品评论</title>
		
		
	</head>
	<body background="white">
		<div id="container">
			<h4>订单信息</h4>
			<p>订单编号:{{order.orderId}}</p>
			<hr>
			<ul>
				<li v-for="item in order.orderItems">
					<div>
						<div style="height: 60px; background:lightgoldenrodyellow; border: 1px darkgrey; width: 600px;">
						<img :src="'static/pimgs/'+item.productImg" height="30">
						{{item.productName}}
						</div>
						<p>
						评价类型：<input type="radio" value="1" v-model="comm_type"/>好评
								<input type="radio" value="0" v-model="comm_type"/>中评
								<input type="radio" value="-1" v-model="comm_type"/>差评
						</p>
						<p>
						是否匿名：<input type="radio" value="1" v-model="is_anonymous"/>匿名
								<input type="radio" value="0" v-model="is_anonymous"/>不匿名
						</p>
						评价内容：<textarea rows="4" cols="40" v-model="comm_content"></textarea>
					</div>
					
				</li>
				
			</ul>
			
			<input type="button" value="提交" @click="addComment"/>
		</div>
		<script type="text/javascript" src="static/js/vue.js" ></script>
		<script type="text/javascript" src="static/js/axios.min.js" ></script>
		<script type="text/javascript" src="static/js/base.js" ></script>
		<script type="text/javascript" src="static/js/cookie_utils.js" ></script>
		<script type="text/javascript" src="static/js/index.js" ></script>
		
		
	
		<script type="text/javascript">
  
			
			var vm = new Vue({
				el:"#container",
				data:{
					order:{},
					comm_type: 1,
					is_anonymous: 0,
					comm_content:""
				},
				created:function(){
					//获取到订单信息
					var jsonstr = localStorage.getItem("order");
					if(jsonstr != null){
						localStorage.removeItem("order");
						this.order = eval("("+jsonstr+")");
						console.log(this.order);
					}
					
				},
				methods:{
					addComment:function(){
						var token = getCookieValue("token");
						var userId = this.order.userId;
						var productId = this.order.orderItems[0].productId;
						var orderId = this.order.orderItems[0].orderId;
						var productName = this.order.orderItems[0].productName;
						
						
						var productComment = {
								"commContent": this.comm_content,
								"commType": this.comm_type,     //好评、中评、差评
								"commLevel": 1,
								"isAnonymous": this.is_anonymous, //是否匿名
								"isShow": 1,      //需要选择的
								"orderItemId": orderId,
								"productId": productId,
								"productName": productName,
								"userId":userId
						};
						
						var url1 = baseUrl + "product/AddComment";
						
						axios({
							url:url1,
							method:"post",
							headers:{
								token:token
							},
							data: productComment
						}).then((res)=>{
							console.log(res);
							if(res.data.code == 10000) {
								//添加购物车成功
								alert("评论成功！");
							} else if(res.data.code == 10001) {
								//加入购物车失败
								alert("评论失败！");
							} else {
								var str = "";
								if(res.data.code == 20001) {
									str = "你还未登陆，请先登录！";
								} else if(res.data.code == 20002) {
									str = "登录过期，请重新登录!";
								}
								var params = "tips="+str+"&returnUrl=user-commentadd.html";
								var loginUrl = "login.html?" + params;
								window.location.href = encodeURI(loginUrl);
							}
						});
					}
				}
			});
		</script>
	</body>
</html>
